<?php 
/**
 * Building Template for Room Booking component
 */
defined('_JEXEC') or die('Restricted access'); 
$js="function submitbutton(pressbutton) {

     var opening_hour = document.getElementById('opening_hour').value-1;
     var opening_minute = document.getElementById('opening_minute').value;
     var opening = new Date();
     opening.setUTCHours(opening_hour,opening_minute);
     var closing_hour  = document.getElementById('closing_hour').value-1;
     var closing_minute = document.getElementById('closing_minute').value;
     var closing = new Date();
     closing.setUTCHours(closing_hour,closing_minute);
    	
      var form = document.adminForm;
      
      if (pressbutton == 'cancel') {
      	submitform( pressbutton );
      	return;
      }
      // do field validation
       if (form.name.value == ''){
           alert('".JText::_( 'SPECBUILDNAME', true )."');
      } else if (form.opening_hour.value == '' || form.opening_minute.value == '' ){
           alert('".JText::_( 'SPECOPENINGTIME', true )."');
      } else if (form.closing_hour.value == '' || form.closing_minute.value == '') {
           alert('".JText::_( 'SPECCLOSINGTIME', true )."'); 
      } else if (closing<=opening) {
	  	   alert('".JText::_( 'LATERCLOSINGTIME',true )."');
	  } else if (form.orgs.value == '') 
           alert('".JText::_( 'SELECTORGS', true )."'); 
      else
	   submitform( pressbutton );
       }";

$document =& JFactory::getDocument();
$document->addScriptDeclaration($js);

?>

<form action="index.php" method="post" name="adminForm" id="adminForm">
<div class="col100">
	<fieldset class="adminform">
	<?php echo JText::_( 'FIELDSREQUIRED' ); ?>
		<legend><?php echo JText::_( 'BUILDING' ); ?></legend>
		<table class="admintable">
		<?php if ($this->item->id>0)
		echo '<tr>
			<td width="100" align="right" class="key">
				<label  for="id">
					'.JText::_( 'ID' ).':
				</label>
			</td>
			<td>
				<input class="text_area" type="text" name="id" id="id" size="10" disabled="disabled" value="'.$this->item->id.'" />
			</td>
		</tr>';?>
		<tr>
			<td width="100" align="right" class="key">
				<label for="name">
					<?php echo JText::_( 'NAME' ); ?>*:
				</label>
			</td>
			<td>
				<input class="text_area" type="text" name="name" id="name" style="width:300px" maxlength="250" value="<?php echo $this->item->name;?>" />
			</td>
		</tr>
		<tr>
			<td width="100" align="right" class="key">
				<label for="address">
					<?php echo JText::_( 'ADDRESS' ); ?>:
				</label>
			</td>
			<td>
				<input class="text_area" type="text" name="address" id="address" style="width:300px" maxlength="250" value="<?php echo $this->item->address;?>" />
			</td>
		</tr>
		<tr>
			<td width="100" align="right" class="key">
				<label for="opening_hour">
					<?php echo JText::_( 'OPENINGTIME' ); ?>*:
				</label>
			</td>
			<td>
				<?php
					$hours=array();
					$hour = new stdClass();
					$hour->value=null;
					$hour->name='--';
					array_push($hours, $hour);
					for($i=0; $i<=23; $i++){
						$hour = new stdClass();
						if (strlen($i)<2) $i='0'.$i;
							$hour->value=$i;
						$hour->name=$i;
						array_push($hours, $hour);
					}
					$minutes=array();
					$minute= new stdClass();
					$minute->value=null;
					$minute->name='--';
					array_push($minutes, $minute);
					for($i=0; $i<56; $i+=5){
						$minute= new stdClass();
						if ($i<10) $i='0'.$i;
						$minute->value=$i;
						$minute->name=$i;
						array_push($minutes, $minute);
					}
					if(isset($this->item->opening)){
						$selected_hour=explode(':',$this->item->opening);
						$selected_minutes=$selected_hour[1];
						$selected_hour=$selected_hour[0];
					}
					else{
						$selected_hour='--';
						$selected_minutes='--';
					}
					echo JHTML::_('select.genericlist',$hours, 'opening_hour', 'class="inputbox"','value','name',$selected_hour);?>
					<label for="opening_minute">
						:
					</label>
					<?php echo JHTML::_('select.genericlist',$minutes, 'opening_minute', 'class="inputbox "','value','name',$selected_minutes);?>
				
			</td>
		</tr>
		<tr>
			<td width="100" align="right" class="key">
				<label for="closing_hour">
					<?php echo JText::_( 'CLOSINGTIME' ); ?>*:
				</label>
			</td>
			<td>
				<?php				
					if(isset($this->item->closing)){
						$selected_hour=explode(':',$this->item->closing);
						$selected_minutes=$selected_hour[1];
						$selected_hour=$selected_hour[0];
					}
					else{
						$selected_hour='--';
						$selected_minutes='--';
					}
					echo JHTML::_('select.genericlist',$hours, 'closing_hour', 'class="inputbox"','value','name',$selected_hour);?>
					<label for="closing_minute">
						:
					</label>
					<?php echo JHTML::_('select.genericlist',$minutes, 'closing_minute', 'class="inputbox "','value','name',$selected_minutes);?>
			</td>
		</tr>
		<tr>
			<td width="100" align="right" class="key">
				<label for="we_opening">
					<?php echo JText::_( 'WEOPEN' ); ?>:
				</label>
			</td>
			<td>
				<?php echo $this->we_opening; ?>
			</td>
		</tr>
		<tr>
			<td width="100" align="right" class="key">
				<label for="orgs[]">
					<?php echo JText::_( 'ORGS' ); ?>*:
				</label>
			</td>
			<td>
				<?php echo $this->organizations; ?>
			</td>
		</tr>
	</table>
	</fieldset>
</div>
<div class="clr"></div>

<input type="hidden" name="option" value="com_roombooking" />
<input type="hidden" name="id" value="<?php echo $this->item->id; ?>" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="controller" value="building" />
</form>
